<template>
  <div class="dashboard-editor-container">
    <panel-group />
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <div class="chart-wrapper">
        <monthly-usage :chart-data="monthlyUsageData" />
      </div>
    </el-row>
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <div class="chart-wrapper">
        <revenue-trends :chart-data="revenueTrendsData" />
      </div>
    </el-row>
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <div class="chart-wrapper">
        <year-water-usage :chart-data="yearWaterUsageData" />
      </div>
    </el-row>
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <div class="chart-wrapper">
        <device-meter :chart-data="deviceMeterRateData" />
      </div>
    </el-row>
  </div>
</template>

<script>
import PanelGroup from './components/PanelGroup'
import { waterMonthlyReceive, waterMonthlyUsage, yearWaterUsage, deviceMeterRate } from '@/api/analysis'
import MonthlyUsage from '@/views/dashboard/admin/components/MothlyUsage.vue'
import RevenueTrends from '@/views/dashboard/admin/components/RevenueTrends.vue'
import YearWaterUsage from '@/views/dashboard/admin/components/YearWaterUsage.vue'
import DeviceMeter from '@/views/dashboard/admin/components/DeviceMeter.vue'
export default {
  name: 'DashboardAdmin',
  components: {
    DeviceMeter,
    YearWaterUsage,
    RevenueTrends,
    PanelGroup,
    MonthlyUsage
  },
  data() {
    return {
      monthlyUsageData: [],
      revenueTrendsData: [],
      yearWaterUsageData: [],
      deviceMeterRateData: []
    }
  },
  created() {
    this.fetchRevenueTrendsData()
    this.fetchWaterUsage()
    this.fetchWaterYearlyUsage()
    this.fetchDeviceMeterRate()
  },
  methods: {
    fetchWaterUsage() {
      waterMonthlyUsage({}).then(res => {
        if (res.code === 20000) {
          this.monthlyUsageData = res.data.list
        }
      })
    },
    fetchRevenueTrendsData() {
      waterMonthlyReceive({}).then(res => {
        if (res.code === 20000) {
          this.revenueTrendsData = res.data.list
        }
      })
    },
    fetchWaterYearlyUsage() {
      yearWaterUsage({}).then(res => {
        if (res.code === 20000) {
          this.yearWaterUsageData = res.data.list
        }
      })
    },
    fetchDeviceMeterRate() {
      deviceMeterRate({}).then(res => {
        if (res.code === 20000) {
          this.deviceMeterRateData = res.data.list
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 0.8em 1em;
  background-color: rgb(240, 242, 245);
  position: relative;

  .github-corner {
    position: absolute;
    top: 0px;
    border: 0;
    right: 0;
  }

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
